//
//  ViewController.m
//  Jpod
//
//  Created by zenox on 2021/10/25.
//

#import "ViewController.h"
#import "JPAlertVC.h"
#import "JPPhotoViewController.h"
#import "TYFDataReviewPictureCell.h"
#import "JPVideoVC.h"
#import <AVFoundation/AVFoundation.h>
#import "JPview.h"
#import "JPRedViewController.h"
#import "JPMoviewPlayerController.h"

@interface ViewController ()<UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>
/* 图片collectionView */
@property (nonatomic, strong) UICollectionView *collectionView;

@end

@implementation ViewController
//- (UIView *)getVedioActionSheetView {
//    
//    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 160 + KSafeAreaHeight)];
//    bgView.backgroundColor = [UIColor whiteColor];
//    {
//        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        [btn setTitle:@"相册" forState:UIControlStateNormal];
//        btn.backgroundColor = [UIColor whiteColor];
//        btn.frame = CGRectMake(0, 0, SCREEN_WIDTH, 50);
//        [bgView addSubview:btn];
//        [btn addTarget:self action:@selector(showUserAlbum) forControlEvents:UIControlEventTouchUpInside];
//    }
//    {
//        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 50.0, SCREEN_WIDTH, 0.5)];
//        line.backgroundColor = [UIColor blackColor];
//        [bgView addSubview:line];
//    }
//    {
//        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        [btn setTitle:@"视频" forState:UIControlStateNormal];
//        btn.backgroundColor = [UIColor whiteColor];
//        btn.frame = CGRectMake(0, 50.5, SCREEN_WIDTH, 50);
//        [bgView addSubview:btn];
//        [btn addTarget:self action:@selector(takeVideo) forControlEvents:UIControlEventTouchUpInside];
//    }
//    {
//        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 100, SCREEN_WIDTH, 10)];
//        line.backgroundColor = [UIColor blackColor];
//        [bgView addSubview:line];
//    }
//    {
//        UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
//        [btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        [btn1 setTitle:@"取消" forState:UIControlStateNormal];
//        btn1.frame = CGRectMake(0, 120, SCREEN_WIDTH, 50);
//        btn1.backgroundColor = [UIColor whiteColor];
//        [bgView addSubview:btn1];
//        [btn1 addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
//    }
//    
//    return bgView;
//}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    JPPhotoViewController *alert = [[JPPhotoViewController alloc] init];

    [self presentViewController:alert animated:YES completion:^{}];
    
//    [self.view addSubview:view];
//    [[UIApplication sharedApplication].windows addSubview:view];
    
}

-(void)arryandstring{
    
    id objects[10] = {@"abbb",@"bczdfasdf",@"casdfasdf",@"asdfasdf"};
    
    NSArray *array = [NSArray arrayWithObjects:objects count:2];
    
//    - (void)insertObject:(id)anObject
//    - (void)removeObjectAtIndex:(NSUInteger)index;
//    - (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject;
    
    array = [array arrayByAddingObject:@"1"];
    array = [array arrayByAddingObject:@"2"];
    array = [array arrayByAddingObject:@"1"];
    array = [array arrayByAddingObject:@"1"];
    
 
    
    NSMutableArray *arr = [[NSMutableArray alloc] initWithCapacity:10];
    [arr addObject:@"1"];
    for (int i=0; i< 9; i++) {
        [arr addObject:@""];
    }
    
//    [arr addObject:@"1"];
//    [arr addObject:@"2"];
//    [arr addObject:@"3"];
//    [arr addObject:@"4"];
//    [arr addObject:@"5"];
    
//    [arr ];
    NSLog(@"array1 = %@",arr);

    [arr replaceObjectAtIndex:0 withObject:@"10"];
//    [arr removeObject:@"1"];
//    [arr removeObjectAtIndex:2];
    NSLog(@"array = %@",arr);
    
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    NSArray *arr = @[@(3),@(4),@(2),@(1)];
    
NSMutableArray *result1 = [arr sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
    return [obj1 compare:obj2];
}];
    NSArray *result = [arr sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        return [obj1 compare:obj2];
    }];
    
    NSLog(@"== %@",result1);
    
    // Do any additional setup after loading the view.
//    JPPhotoViewController *alert = [[JPPhotoViewController alloc] init];
//
//    [self presentViewController:alert animated:YES completion:^{}];
    self.view.backgroundColor = [UIColor grayColor];
//    JPview *view = [[JPview alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, self.view.frame.size.height - 100)];
////    [self.view addSubview:view];
//    [[UIApplication sharedApplication].keyWindow addSubview:view];
    
//    [self.view addSubview:self.collectionView];
//    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.edges.mas_equalTo(0);
//    }];
   
    

         // 本地资源文件
//    NSString *filePath = @"file:///var/mobile/Media/DCIM/100APPLE/IMG_0023.MOV";
//         // 2. 创建视频播放控制器
//    UIPageViewController *playerViewController = [[UIPageViewController alloc] init];
//        // 3. 设置视频播放器 (这里为了简便,使用了URL方式,同样支持playerWithPlayerItem:的方式)
//        playerViewController.player = [AVPlayer playerWithURL:[NSURL fileURLWithPath:filePath]];
//        // 4. modal展示
//        [self.targetVC presentViewController:playerViewController animated:YES completion:nil];
//        // 5. 开始播放 : 默认不会自动播放
//        [playerViewController.player play];
    
    
}

- (UICollectionView *)collectionView {

    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.minimumLineSpacing = 20;
        layout.minimumInteritemSpacing = 0;
        layout.sectionInset = UIEdgeInsetsMake(10, 14, 0, 14);
        layout.itemSize = CGSizeMake(50, 50);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.showsVerticalScrollIndicator = NO;
//        _collectionView.alwaysBounceHorizontal = YES;
        _collectionView.backgroundColor = [UIColor redColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.scrollEnabled = NO;
        [_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass(TYFDataReviewPictureCell.class) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass(TYFDataReviewPictureCell.class)];
    }
    return _collectionView;
}

//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//    NSLog(@"touchesBegan");
//    JPPhotoViewController *vc = [[JPPhotoViewController alloc] init];
//    [self presentViewController:vc animated:YES completion:nil];
//}

- (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    TYFDataReviewPictureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(TYFDataReviewPictureCell.class) forIndexPath:indexPath];
    
    return cell;
}

- (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (section == 0) {
        return 12;
    }else{
        return 4;
    }
}


@end
